package com.gitee.sys.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gitee.mybase.top.entity.ShopInfo;
import com.gitee.sys.service.IShopInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chengkaimao
 * @since 2018-11-17
 */
@RestController
@RequestMapping("/sys/shop-info")
@Api("店铺信息相关的api")
public class ShopInfoController {

    @Reference
    private IShopInfoService shopInfoService;

    @ApiOperation(value = "店铺信息分页查询", notes = "店铺信息分页查询", httpMethod = "GET")
    @ApiImplicitParams({@ApiImplicitParam(name = "current", value = "当前页", paramType = "query", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "size", value = "每页条数", paramType = "query", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "shopCode", value = "店铺编码", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "shopName", value = "店铺名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "shopShortName", value = "店铺简称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "rootIn", value = "来源于", paramType = "query", dataType = "String")})
    @GetMapping("page")
    public ResponseEntity<IPage<ShopInfo>> getPage(@RequestParam long current, @RequestParam long size, @ApiIgnore ShopInfo shopInfo) {
        IPage<ShopInfo> page = shopInfoService.getPage(current, size, shopInfo);
        return ResponseEntity.ok(page);
    }

    @PostMapping
    @ApiOperation(value = "新增店铺信息", notes = "新增店铺信息", httpMethod = "POST")
    public ResponseEntity<Void> saveBaseDict(@RequestBody ShopInfo shopInfo) {
        shopInfoService.saveShop(shopInfo);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @PutMapping
    @ApiOperation(value = "更新店铺信息", notes = "更新店铺信息", httpMethod = "PUT")
    public ResponseEntity<Void> updateBaseDict(@RequestBody ShopInfo shopInfo) {
        shopInfoService.updateShop(shopInfo);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();

    }

    @DeleteMapping
    @ApiOperation(value = "删除店铺信息", notes = "删除店铺信息", httpMethod = "DELETE")
    public ResponseEntity<Void> deleteBaseDict(@RequestParam String shopCode) {
        shopInfoService.delShop(shopCode);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

}
